# 定义显示雷达图需要的色标，张深寿，2021-10-22
import matplotlib as mpl
import numpy as np

#色标，反射率
colos_R = (
    np.array([0, 172, 164])/255.0,
    np.array([192, 192, 254])/255.0,
    np.array([122, 114, 238])/255.0,
    np.array([30, 38, 208])/255.0,
    np.array([166, 252, 168])/255.0,
    np.array([0, 234, 0])/255.0,
    np.array([16, 140, 26])/255.0,
    np.array([252, 244, 100])/255.0,
    np.array([200, 200, 2])/255.0,
    np.array([140, 140, 0])/255.0,
    np.array([254, 172, 172])/255.0,
    np.array([254, 100, 92])/255.0,
    np.array([238, 2, 48])/255.0,
    np.array([212, 142, 254])/255.0,
    np.array([170, 35, 250])/255.0
    )
#色标，速度
colos_V = (
    np.array([126, 224, 254])/255.0,
    np.array([0, 224, 254])/255.0,
    np.array([0, 176, 176])/255.0,
    np.array([0, 254, 0])/255.0,
    np.array([0, 196, 0])/255.0,
    np.array([0, 128, 0])/255.0,
    np.array([200, 200, 200])/255.0,
    np.array([200, 200, 200])/255.0,
    np.array([254, 0, 0])/255.0,
    np.array([254, 88, 88])/255.0,
    np.array([254, 176, 176])/255.0,
    np.array([254, 124, 0])/255.0,
    np.array([254, 210, 0])/255.0,
    np.array([254, 254, 0])/255.0,
    np.array([124, 0, 124])/255.0
    )
#色标，谱宽
colos_W = (
    np.array([224, 224, 224])/255.0,
    np.array([124, 224, 224])/255.0,
    np.array([0, 224, 224])/255.0,
    np.array([0, 176, 176])/255.0,
    np.array([0, 254, 254])/255.0,
    np.array([0, 196, 0])/255.0,
    np.array([0, 128, 0])/255.0,
    np.array([254, 254, 0])/255.0,
    np.array([254, 210, 0])/255.0,
    np.array([254, 124, 0])/255.0,
    np.array([254, 176, 176])/255.0,
    np.array([254, 88, 88])/255.0,
    np.array([254, 0, 0])/255.0,
    np.array([254, 254, 254])/255.0,
    np.array([124, 0, 124])/255.0
    )
#色标，差分相移率，KDP
colos_KDP = (
    np.array([0,255,255])/255.0,
    np.array([0,239,239])/255.0,
    np.array([0,173,173])/255.0,
    np.array([181,181,181])/255.0,
    np.array([181,181,181])/255.0,
    np.array([0,198,33])/255.0,
    np.array([0,239,8])/255.0,
    np.array([33,255,33])/255.0,
    np.array([255,255,24])/255.0,
    np.array([255,231,0])/255.0,
    np.array([255,189,0])/255.0,
    np.array([255,156,0])/255.0,
    np.array([255,90,0])/255.0,
    np.array([247,8,0])/255.0,
    np.array([189,0,57])/255.0,
    np.array([255,0,255])/255.0
    )
#色标，相关系数。差分相移的色标颜色和它相同
colos_CC = (
    np.array([0,60,255])/255.0,
    np.array([0,239,239])/255.0,
    np.array([0,186,191])/255.0,
    np.array([0,131,125])/255.0,
    np.array([0,137,56])/255.0,
    np.array([0,183,41])/255.0,
    np.array([0,218,13])/255.0,
    np.array([0,255,0])/255.0,
    np.array([255,255,59])/255.0,
    np.array([255,240,0])/255.0,
    np.array([255,198,0])/255.0,
    np.array([255,165,0])/255.0,
    np.array([255,114,0])/255.0,
    np.array([255,31,0])/255.0,
    np.array([193,0,0])/255.0,
    np.array([212,0,170])/255.0
    )
#色标，差分反射率，ZDR
colos_ZDR = (
    np.array([70,70,70])/255.0,
    np.array([110,110,110])/255.0,
    np.array([150,150,150])/255.0,
    np.array([200,200,200])/255.0,
    np.array([220,240,220])/255.0,
    np.array([0,192,39])/255.0,
    np.array([0,232,10])/255.0,
    np.array([36,255,36])/255.0,
    np.array([255,255,30])/255.0,
    np.array([255,230,0])/255.0,
    np.array([255,188,0])/255.0,
    np.array([255,152,0])/255.0,
    np.array([255,94,0])/255.0,
    np.array([242,15,0])/255.0,
    np.array([187,0,58])/255.0,
    np.array([255,0,255])/255.0
    )

# 生成色标和色标相应的值
# 反射率
cm_Ref = mpl.colors.ListedColormap(colos_R)
levels1 = [-5,0,5,10,15,20,25,30,35,40,45,50,55,60,65,70]  # 反射率等级
normR = mpl.colors.BoundaryNorm(levels1, cm_Ref.N)

# 多普勒速度
cm_V = mpl.colors.ListedColormap(colos_V)
levels2 = [-999, -27, -20, -15, -10, -5, -1, 0, 1, 5, 10, 15, 20, 27, 999]  # V等级
normV = mpl.colors.BoundaryNorm(levels2, cm_V.N)

# 谱宽
cm_W = mpl.colors.ListedColormap(colos_W)
levels3 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 999]  # W等级
normW = mpl.colors.BoundaryNorm(levels3, cm_W.N)

# 差分相移率
cm_KDP = mpl.colors.ListedColormap(colos_KDP)
levels4 = [-0.8, -0.4, -0.2, -0.1, 0.1, 0.15, 0.22, 0.33, 0.5, 0.75, 1.1, 1.7, 2.4, 3.1, 7, 20]  # KDP等级
normKDP = mpl.colors.BoundaryNorm(levels4, cm_KDP.N)

# 相关系数
cm_CC = mpl.colors.ListedColormap(colos_CC)
levels5 = [0, 0.1, 0.3, 0.5, 0.6, 0.7, 0.8, 0.85, 0.9, 0.92, 0.94, 0.95, 0.97, 0.98, 0.99, 1.0]  # CC等级
normCC = mpl.colors.BoundaryNorm(levels5, cm_CC.N)

# 差分反射率
cm_ZDR = mpl.colors.ListedColormap(colos_ZDR)
levels6 = [-4, -3, -2, -1, 0, 0.2, 0.5, 0.8, 1, 1.5, 2, 2.5, 3, 3.5, 4, 5]  # ZDR等级
normZDR = mpl.colors.BoundaryNorm(levels6, cm_ZDR.N)

# 差分相移，PhiDP
levels7 = [0, 24, 48, 72, 96, 120, 144, 168, 192, 216, 240, 264, 288, 312, 336, 360]  # PhiDP等级
normPhiDP = mpl.colors.BoundaryNorm(levels7, cm_CC.N)